from oauth2client.client import OAuth2WebServerFlow
from oauth2client.file import Storage
from oauth2client.tools import run
import httplib2

def authorize():
    flow = OAuth2WebServerFlow(
                        client_id='264844954553.apps.googleusercontent.com',
                        client_secret='yGGizLWEJevucn0Qi6RCqjM7',
                        scope='https://spreadsheets.google.com/feeds',
                        user_agent='ITRC-recorder/0.1')
    storage = Storage(r'C:\Windows\Temp\auth.dat')
    credentials = storage.get()
    if credentials is None or credentials.invalid == True:
        credentials = run(flow, storage)

    http = httplib2.Http()
    http = credentials.authorize(http)
    return http
#    calsvc = build(serviceName='calendar', version='v3', http=http,
#                                developerKey='AIzaSyBMAIE0lB9ElpVLJ9kb0N_lnda8nHun0cg')